package com.shenmazong.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2022/6/30 11:45
 */

@Configuration
public class RabbitmqConfig {

    /**
     * @description 简单模式队列
     * @author 军哥
     * @date 2022/6/30 16:10
     * @version 1.0
     */
    @Bean
    public Queue simpleQueue() {
        return new Queue("simpleQueue");
    }

    /**
     * @description 工作模式
     * @author 军哥
     * @date 2022/6/30 16:11
     * @version 1.0
     */
    @Bean
    public Queue workQueue() {
        return new Queue("workQueue");
    }

    //===== 发布订阅模式 开始

    @Bean
    public Queue publishQueueA() {
        return new Queue("publishQueueA");
    }
    @Bean
    public Queue publishQueueB() {
        return new Queue("publishQueueB");
    }
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }
    @Bean
    public Binding bindingA() {
        return BindingBuilder.bind(publishQueueA()).to(fanoutExchange());
    }
    @Bean
    public Binding bindingB() {
        return BindingBuilder.bind(publishQueueB()).to(fanoutExchange());
    }

    //===== 发布订阅模式 结束


    //===== 路由模式 开始
    @Bean
    public Queue directQueueA() {
        return new Queue("directQueueA");
    }
    @Bean
    public Queue directQueueB() {
        return new Queue("directQueueB");
    }
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("directExchange");
    }
    @Bean
    public Binding bindingDirectA() {
        // routingkey相当于快递地址
        return BindingBuilder.bind(directQueueA()).to(directExchange()).with("msg.login");
    }
    @Bean
    public Binding bindingDirectB() {
        return BindingBuilder.bind(directQueueB()).to(directExchange()).with("msg.order");
    }
    //===== 路由模式 结束


    //===== 主题模式 开始
    @Bean
    public Queue topicQueueA() {
        return new Queue("topicQueueA");
    }
    @Bean
    public Queue topicQueueB() {
        return new Queue("topicQueueB");
    }
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topicExchange");
    }
    @Bean
    public Binding bindingTopicA() {
        // routingkey相当于快递地址
        return BindingBuilder.bind(topicQueueA()).to(topicExchange()).with("msg.login");
    }
    @Bean
    public Binding bindingTopicB() {
        return BindingBuilder.bind(topicQueueB()).to(topicExchange()).with("msg.*");
    }
    //===== 主题模式 结束
}
